
var myData = Ext.define('result',{
	extend: 'Ext.data.Model',
	fields: []
});

    // create the data store
var app_store = Ext.create('Ext.data.Store', {
        model: 'result',
        autoLoad: true,
	autoSync:true,
        proxy: {
		type: 'ajax',
		url: 'display.php',
		reader: {
		        type: 'xml',
		        record: 'line',
		        idProperty: 'Id',
		        totalRecords: '@total'
            	}
        }
});

var searchGrid = Ext.create('Ext.grid.Panel', {
	store: app_store,
	columns: [],
 viewConfig: {
  forceFit: true
}
 
 
});


///////////////////////////////////

var fields ;
var columns2 ; 
var app_fields = new Array() ;

var  app_columns = [{
	text: 'ID',
	sortable: true,
	dataIndex: 'id'
}]; 

var field = new Array();

var fields ;
var newStore ;
var newColumns ;


var combostore = Ext.create('Ext.data.Store', {
	autoLoad: true,
	autoSync:true,
	fields: ['name','value'],
	proxy: {
		type: 'ajax',
		url: 'getAppNames.php',
		reader: {
			type: 'xml',
			root: 'applications',
			record: 'application' 
		}
	}
});

var searchCmb = Ext.create('Ext.form.ComboBox',{
	fieldLabel: 'Select an application',
	store: combostore,
	hiddenName: 'id',
	displayField: 'name',
	valueField:'value',
 
	listeners:{
		 	'select': function( ) {

			fields = searchCmb.getValue( ) ;
			field = fields.split('|');
			for (var i = 0; i < field.length; i++) {
				app_fields[i] =  {
					name: field[i]
				};
				app_columns[i] = {
					text: field[i],
					sortable: true,
					dataIndex: field[i],
				};
			}
			columns2 = Ext.grid.column.Column({columns:app_columns});
			searchGrid.update( );
			fields = ['totally', {name : 'dynamic', type : 'string'}];
			newColumns = app_columns;
		}
	}
});



var search_button = Ext.create('Ext.Button', {
	text: 'Click me',
 
	handler: function() {
		Ext.define('result',{
			extend: 'Ext.data.Model',
			fields: [
				{name: 'User', mapping: 'LineAttributes > User'},
				'Status', 'App', 'Filename'
			]
		});
		newStore = Ext.create('Ext.data.Store', {
			model: 'result',
			autoLoad: true,
			autoSync:true,
			proxy: {
				type: 'ajax',
				url: 'display.php',
				reader: {
					type: 'xml',
					record: 'line',
					idProperty: 'Id',
					totalRecords: '@total'
				}
			}
		});
		searchGrid.reconfigure(newStore, newColumns);
		searchGrid.show();
		app_fields = [];
		app_columns = [];
	}
});



var search_panel = Ext.create('Ext.Panel', {
 
    height: 800,
 border: false,
	 	defaults: {
  	 		border: false
	 	},
 layout: {
        	type: 'vbox',
        	align: 'center'
    	},
  
items: [searchCmb, search_button, searchGrid]

  
});
  






